﻿using Bear.Library.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Bear.Models
{
    [Serializable]
    public class Script
    {
        /// <summary>
        /// 脚本名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 脚本说明
        /// </summary>
        public string Decscription { get; set; }


        public string Path { get; set; }
    }

    [Serializable]
    public class Scripts : List<Script>
    {
        public const string DIRECTORY_PATH = "Scripts";


        public static Scripts Load()
        {
            Scripts scripts = new Scripts();

            if (!Directory.Exists(DIRECTORY_PATH))
            {
                Directory.CreateDirectory(DIRECTORY_PATH);
            }

            foreach (var item in Directory.GetFiles(DIRECTORY_PATH, "*.cs"))
            {
                try
                {
                    Script script = new Script()
                    {
                        Name = Path.GetFileNameWithoutExtension(item),
                        Path = item
                    };
                    scripts.Add(script);
                }
                catch { }
            }

            return scripts;

        }
    
    }
}
